package com.han.fu.api.business.service.impl;

import com.han.fu.api.business.entity.User;
import com.han.fu.api.business.service.IUserService;
import com.han.fu.api.common.model.UserDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @author star
 * @version 1.0.0
 * @Description: UserDetailsServiceImpl
 * @date 2020/7/21
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    IUserService userService;

    @Override
    public UserDetails loadUserByUsername(String account) throws UsernameNotFoundException {
        UserDetail userDetail = new UserDetail();
        User user = userService.queryUserByAccount(account);
        userDetail.setId(user.getId());
        userDetail.setName(user.getName());
        userDetail.setExpire(user.getExpire());
        userDetail.setRole(user.getRole());
        userDetail.setPassword(user.getPassword());
        userDetail.setPhone(user.getPhone());
        userDetail.setAccount(user.getAccount());
        userDetail.setCity(user.getCity());
        return userDetail;
    }

}
